package com.remenote.remenoteback.entity.vo;

import com.remenote.remenoteback.entity.doo.CardDo;
import com.remenote.remenoteback.entity.doo.DeckDo;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: remenote-back
 * @BelongsPackage: com.remenote.remenoteback.entity.vo
 * @Author: 23392
 * @CreateTime: 2024-03-16  17:30
 * @Description: TODO
 * @Version: 1.0
 */
@Getter
@Setter
@Accessors(chain = true)
public class DeckVo {
    public Integer deckId;
    public String deckName;
    public List<CardVo> cardList;

    public static DeckVo fromDeckDoAndCardList(DeckDo deckDo, List<CardDo> cardDos) {
        return new DeckVo()
                .setDeckName(deckDo.getDeckName())
                .setDeckId(deckDo.getId())
                .setCardList(CardVo.fromCardDos(cardDos));
    }
//    public static DeckVo fromCardDosToDeckVo(List<CardDo> cardDos) {
//        String deckName=cardDos.get(0).getDeckName();
//        List<CardVo> cardVos = new ArrayList<>();
//        for (CardDo cardDo : cardDos) {
//           cardVos.add( CardVo.fromCardDo(cardDo));
//        }
//        return new DeckVo()
//                .setDeckName(deckName)
//                .setCardList(cardVos);
//    }
//    public static List<DeckVo> fromCardDos(List<CardDo> cardDos) {
//        Map<String, DeckVo> deckMap = new HashMap<>();
//        for (CardDo cardDo : cardDos) {
//            String deckName = cardDo.getDeckName();
//            DeckVo deckVo = deckMap.get(deckName);
//            if (deckVo == null) {
//                deckVo = new DeckVo().setDeckName(deckName);
//                deckVo.setCardList(new ArrayList<>());
//                deckMap.put(deckName, deckVo);
//            }
//            deckVo.getCardList().add(CardVo.fromCardDo(cardDo));
//        }
//        return new ArrayList<>(deckMap.values());
//    }

}
